from flask import request, Blueprint
from model.admin import addNavlist, getNavlist, delNavlist

admin = Blueprint('admin', __name__)


@admin.route("/addnavlist", methods=["POST", "GET"])
def addNav():
    if request.method == "POST":
        data = request.get_json()
        userid = data['userid']
        url = data['url']
        token = data["token"]
        category = data["category"]
        navname = data["navname"]
        img = data["img"]
        info = addNavlist(userid, url, img, category, navname, token)
        return info
    else:
        return "不支持GET方法"


@admin.route("/getnavlist", methods=["POST", "GET"])
def getNav():
    if request.method == "POST":
        return "不支持POST方法"
    else:
        userid = request.args.get("userid")
        token = request.args.get("token")
        info = getNavlist(userid, token)
        return info


@admin.route("/delnavlist", methods=["POST", "GET"])
def delNav():
    if request.method == "POST":
        data = request.get_json()
        userid = data['userid']
        navid = data['navid']
        token = data["token"]
        info = delNavlist(userid, navid, token)
        return info
    else:
        return "不支持GET方法"
